package com.unismc.charge.collector.controller;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.gitee.loyo.BusinessService;
import com.gitee.loyo.Request;
import com.gitee.loyo.StationService;
import com.gitee.loyo.config.ChargeNotifyProperties;
import com.gitee.loyo.config.ChargeProperties;
import com.gitee.loyo.post.QueryStationStatsPost;
import com.gitee.loyo.post.QueryStationStatusPost;
import com.gitee.loyo.post.QueryStationsPost;
import com.google.common.collect.Lists;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;

/**
 * @author: Forward Seen
 * @description:
 * @createTime: 2024/4/10 17:36
 * @since: 1.0
 */
@Slf4j
@RestController
@RequestMapping("/test")
public class ChargeStationTestController {

    @Autowired
    ChargeProperties chargeProperties;
    @Autowired
    ChargeNotifyProperties chargeNotifyProperties;
    @Autowired
    StationService stationService;
    @Autowired
    BusinessService businessService;
    @Autowired
    ObjectMapper objectMapper;

    @PostMapping("testQueryStationsInfo")
    public void testQueryStationsInfo() throws JsonProcessingException {
        QueryStationsPost post = new QueryStationsPost().setPageNo(1).setPageSize(10);
        System.out.println(
                objectMapper.writeValueAsString(
                        stationService.queryStationsInfo(new Request<>(chargeProperties.getOperatorId(), post))
                )
        );
    }

    @PostMapping("testQueryStationsStatus")
    public void testQueryStationsStatus() throws JsonProcessingException {
        QueryStationStatusPost post = new QueryStationStatusPost().setStationIds(Lists.newArrayList("12"));
        System.out.println(
                objectMapper.writeValueAsString(
                        stationService.queryStationStatus(new Request<>(chargeProperties.getOperatorId(), post))
                )
        );
    }

    @PostMapping("testQueryStationsStats")
    public void testQueryStationsStats() throws JsonProcessingException {
        QueryStationStatsPost post = new QueryStationStatsPost().setStationId("12")
                .setStartTime(LocalDate.now().minusDays(1).format(DateTimeFormatter.ofPattern("yyyy-MM-dd")))
                .setEndTime(LocalDate.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd")));
        System.out.println(
                objectMapper.writeValueAsString(
                        stationService.queryStationStats(new Request<>(chargeProperties.getOperatorId(), post))
                )
        );
    }

    @PostMapping("testQueryStationsInfoCustom")
    public void testQueryStationsInfo(QueryStationsPost post) throws JsonProcessingException {
        System.out.println(
                objectMapper.writeValueAsString(
                        stationService.queryStationsInfo(new Request<>(chargeProperties.getOperatorId(), post))
                )
        );
    }


    @PostMapping("testQueryStationsStatusCustom")
    public void testQueryStationsStatus(QueryStationStatusPost post) throws JsonProcessingException {
        //QueryStationStatusPost post = new QueryStationStatusPost().setStationIds(Lists.newArrayList("12"));
        System.out.println(
                objectMapper.writeValueAsString(
                        stationService.queryStationStatus(new Request<>(chargeProperties.getOperatorId(), post))
                )
        );
    }

    @PostMapping("testQueryStationsStatsCustom")
    public void testQueryStationsStats(QueryStationStatsPost post) throws JsonProcessingException {
        //QueryStationStatsPost post = new QueryStationStatsPost().setStationId("12")
        //        .setStartTime(LocalDate.now().minusDays(1).format(DateTimeFormatter.ofPattern("yyyy-MM-dd")))
        //        .setEndTime(LocalDate.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd")));
        System.out.println(
                objectMapper.writeValueAsString(
                        stationService.queryStationStats(new Request<>(chargeProperties.getOperatorId(), post))
                )
        );
    }


}
